<style scoped>
.search_box_item{
    width: 100%;
    margin-top: 10px;
    display: flex;
    flex-direction: row;
}
.search_box_item span{
    display: inline-block;
    margin-right: 10px;
    font-size: 20px;
    margin-top: 10px;
}
</style>

<template>
    <div class="search_box_item" @click="toItem">
        <img :src="item.attr5" alt="" width="100px" height="100px">
        <div style="padding-left:10px">
            <div>
                <span>ItemId: {{item.itemid}}</span>
                <span>listprice: {{item.listprice}}</span>
            </div>
            <div v-html="highlightWords(item.attr1)">
                Attribute: {{item.attr1}}
            </div>
            <p style="color:grey" v-html="highlightWords(item.attr2)">
                Describe: {{item.attr2}}
            </p>
        </div>
    </div>
</template>

<script>
import router from '@/router'
export default {
    name: 'search-item',
    props: {
        item: {
            type: Object,
            default (){ return {} }
        },
        keywords: [String, Number]
    },
    data () {
        return {}
    },
    methods:{
        highlightWords(source){
            const highlight = ` <span style="color: red">${this.keywords}</span>`
            const reg = new RegExp(this.keywords, 'gi')
            return source.replace(reg, highlight);
        },
        toItem(){
            console.log("what");
            router.push("/item/"+this.item.itemid);
        }
    }
}
</script>